﻿using System.Collections.Generic;
using System.Windows.Markup;

namespace RSkor.Common.WinForms
{
    [ContentProperty("Controls")]
    public class Form : System.Windows.Forms.Form, IRootObject
    {
        public Form()
            : base()
        {
            MarkupHelper.BeginLoadingRootObject(this);
        }

        private MarkupHelper _rootHelper = null;
        private MarkupHelper RootHelper
        {
            get
            {
                if (_rootHelper == null)
                    _rootHelper = new MarkupHelper(this);
                return _rootHelper;
            }
        }

        public Dictionary<string, object> Resources
        {
            get
            {
                return RootHelper.Resources;
            }
        }
        #region INameScope Members

        public object FindName(string name)
        {
            return RootHelper.FindName(name);
        }

        public void RegisterName(string name, object scopedElement)
        {
            RootHelper.RegisterName(name, scopedElement);
        }

        public void UnregisterName(string name)
        {
            RootHelper.UnregisterName(name);
        }

        #endregion

        #region IRootObject Members

        public IList<ReferenceExtension> UnresolvedReferences
        {
            get { return _rootHelper.UnresolvedReferences; }
        }

        #endregion

        #region IRootObject Members

        public System.Collections.IList Children
        {
            get { return this.Controls; }
        }

        #endregion
    }
}
